package cc.eddic.examinationsystem.dto;

import cc.eddic.examinationsystem.domain.Exam;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotEmpty;
import java.time.LocalDateTime;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class DemoModel {
    private Long id;

    @NotEmpty(message = "名称不能为空")
    private String name;

    private LocalDateTime examAt;
    private Integer timeLimit;

    @Min(value = 1, message = "总分不能小于 1")
    @Max(value = 200, message = "总分不能大于 200")
    private Integer totalScore;

    private Integer version;

    public static DemoModel from(Exam exam) {
        DemoModel demoModel = new DemoModel();
        BeanUtils.copyProperties(exam, demoModel);
        return demoModel;
    }
}
